<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ taglib prefix="c" uri="http://java.sun.com/jstl/core_rt" %>
<c:set var="ctx" value="${pageContext.request.contextPath}"></c:set>
<jsp:include page="../inc.jsp" />
<!DOCTYPE html>
<html>
	<head>
		<meta charset="UTF-8">
		
		<script type="text/javascript">
			$(function(){
				$('#tb').datagrid({
					url:'${ctx}/teacher/find',
					fit:true,
		    		border:true,
		    		striped:true,
		    		singleSelect:true,
		    		rownumbers:true,
		    		pagination:true,
		    		pagePosition:'top',
		    		pageSize:20,
		    		pageList:[5,10,15,20,25],
		    		scrollbarSize:18,
		    		sortName:'loginName',
		    		toolbar:'#tbar',
		    		checkOnSelect:false,
		    		remoteSort:true,
		    		columns:[[{
		    			field:'ck',checkbox:true
		    		},{
		    			field:'loginName',
				        title:'登录名',
				        width:'20%',
				        sortable:true
		    		},{
		    			field:'name',title:'名称',width:100
		    		},{
		    			field:'sex',
		    			title:'性别',
		            	width:'10%',
		            	align:'center',
		            	formatter:function(value,row,index){
		            		if(value=='1'){
		            			value='男';
		            		}else{
		            			value='女';
		            		}
		            		return value;
		            	}
		    		},{
		    			field:'birthday',
		    			title:'出生日期',
		            	width:'15%',
		            	formatter:function(v,r,i){
		            		if(v!=undefined&&v.length>10&&v.length<20){
		            			v = v.substring(0,11);
		            		}
		            		return v;
		            	}
		    		},{
		    			field:'learn',
		            	width:'10%',
		            	hidden:false,
		            	title:'所教课程'
		    		},{
		    			field:'job',
		            	width:'10%',
		            	hidden:false,
		            	title:'职位'
		    		},{
		    			field:'idcard',
		            	width:'10%',
		            	hidden:false,
		            	title:'证件号码'
		    		},{
		    			field:'active',align:'center',
		            	formatter:function(v,r,i){
		            		var str = '<a href=\'#\' onclick=\'editUser('+i+')\'>编辑</a>';
		            		str += '&nbsp;|&nbsp;<a href=\'#\' onclick=\'delUser('+i+')\'>删除</a>'
		            		return str;
		            	}
		    		}]],
		    		onClickRow:function(index,row){
		    			
		    		}
		    		
				});
				//实现表格分页的页面过滤器
				setTimeout(function(){
					$('#tb').datagrid({loadFilter:pagerFilter}).datagrid('loadData');
				},10);
				//$('#tb').datagrid('reload');//刷新数据
				//$('#tb').datagrid('loadData',json);//重新加载数据
			});
			
			function addUser(row){
				var url='${ctx}/teacher/add';
				if(row!=''){
					url='${ctx}/teacher/edit';
				}
				$('#d1').dialog({
					title:'新增或编辑用户',
					width:490,
					height:370,
					modal:true,
					href:'${ctx}/teacher/aoe?row='+row,
					buttons:[{
						text:'保存',
						iconCls:'icon-save',
						handler:function(){
							var f = $('#dataForm');
							if(f.form('validate')){
								var data = f.serialize();
								submitData(url,data);
							}
						}
					},{
						text:'关闭',
						iconCls:'icon-cancel',
						handler:function(){
							$('#d1').dialog('close');
						}
					}]
				});
			}
			
			function editUser(index){
				$('#tb').datagrid('selectRow',index);
				$('#tb').datagrid('checkRow',index);
				$('#tb').datagrid('highlightRow',index);
				var row = $('#tb').datagrid('getSelected');
				row = JSON.stringify(row);
				addUser(row);
			}
			
			function batchDel(){
				var cs = $('#tb').datagrid('getChecked');
				if(!(cs.length>0)){
					$.messager.alert("系统提示",'请选择删除行','info');
					return;
				}
				var ids = '',b=false;
				
				$.each(cs, function(i,c) {
					var id = c.id;
					if(b){
						ids += ",";
					}
					b=true;
					ids += id;
				});
				
				var url = '${ctx}/teacher/removes?ids='+ids;
				var data = '';
				submitData(url,data);
			}
			
			function delUser(index){
				$('#tb').datagrid('selectRow',index);
				$('#tb').datagrid('checkRow',index);
				$('#tb').datagrid('highlightRow',index);
				var row = $('#tb').datagrid('getSelected');
				$.messager.confirm('删除用户','确认要删除该用户信息?',
					function(r){
						if(r){
							var tid = row.id;
							var url = '${ctx}/teacher/remove/'+tid;
							var data = '';
							submitData(url,data);
						}
					});
			}
			
			function searchData(){
				var tname = $('#t1').val();
				$('#tb').datagrid({
					queryParams:{
						name:tname
					}
				});
			}
		</script>
		<title></title>
	</head>
	<body>
		<div id="d1"></div>
		<div id="userLayout" class="easyui-layout" data-options="fit:true">   
		       
		    <div data-options="region:'center',
		    	border:false" 
		    	style="padding:0px;background:#eee;">
		    	
		    	<table id="tb"></table>
		    	
		    	
		    </div>   
		</div>
		<div id="tbar">
			<a class="easyui-linkbutton" onclick="addUser('')"
			 data-options="
				iconCls:'icon-add',
				plain:false
				">新增</a>
			<a class="easyui-linkbutton" onclick="batchDel()"
			 data-options="
				iconCls:'icon-remove',
				plain:false
				">批量删除</a>
			<input style="width: 200px;height: 30px;line-height: 25px" class="easyui-textbox" id="t1" data-options="
				prompt:'输入名称搜索'">
			<a class="easyui-linkbutton" data-options="
				iconCls:'icon-save',
				plain:false
				" onclick="searchData()">搜索</a>	
		</div>
	</body>
</html>
    